# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=exiv2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.27.5
pkgrel=1
pkgdesc="Exif/IPTC/Xmp C++ metadata library and tools (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://exiv2.org/'
license=('GPL-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/Exiv2/${_realname}/archive/v${pkgver}.tar.gz")
sha256sums=('1da1721f84809e4d37b3f106adb18b70b1b0441c860746ce6812bb3df184ed6c')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  cd "${srcdir}"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${MINGW_ARCH} ]] && rm -rf "${srcdir}"/build-${MINGW_ARCH}
  mkdir -p "${srcdir}"/build-${MINGW_ARCH} && cd "${srcdir}"/build-${MINGW_ARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -DEXIV2_ENABLE_VIDEO=ON \
      -DEXIV2_ENABLE_NLS=ON \
      -DEXIV2_ENABLE_WIN_UNICODE=ON \
      -DEXIV2_BUILD_SAMPLES=OFF \
      -DEXIV2_ENABLE_WEBREADY=ON \
      -DEXIV2_ENABLE_CURL=ON \
      -DEXIV2_ENABLE_BMFF=ON \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${MINGW_ARCH}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
